/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.modules.third.jg.report.freight.information.constant.enums;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 河北省平台上报--付款方式代码
 *
 * @author duanlikao
 * @created 2021/1/7
 */
public enum PaymentMeansCodeEnum {

    PAYMENT_MEANS_TYPE_XYZ("1", "信用证"),
    PAYMENT_MEANS_TYPE_TS("2", "托收"),
    PAYMENT_MEANS_TYPE_HF("3", "汇付"),
    PAYMENT_MEANS_TYPE_YHHP("31", "银行汇票"),
    PAYMENT_MEANS_TYPE_YHZZ("32", "银行转账"),
    PAYMENT_MEANS_TYPE_DSPPT("4", "第三方支付平台"),
    PAYMENT_MEANS_TYPE_ZFB("41", "支付宝支付"),
    PAYMENT_MEANS_TYPE_WX("42", "微信支付"),
    PAYMENT_MEANS_TYPE_OTHER("9", "其他电子支付方式（不允许现金支付）"),

    ;

    public final String code;
    public final String msg;

    private static Map<String, PaymentMeansCodeEnum> codeMap = Maps.newHashMap();

    PaymentMeansCodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static String getMsg(String code) {
        return codeMap.containsKey(code) ? codeMap.get(code).msg : StringUtils.EMPTY;
    }

    public static boolean isValid(String code) {
        return codeMap.containsKey(code);
    }

    static {
        for (PaymentMeansCodeEnum status : PaymentMeansCodeEnum.values()) {
            codeMap.put(status.code, status);
        }
    }

    public static PaymentMeansCodeEnum getPaymentMeansCodeEnumByVal(String code) {

//        return Arrays.stream(PaymentMeansCodeEnum.values()).collect(Collectors.toMap(PaymentMeansCodeEnum::getCode, value -> value, (k1, k2) -> k2)).get(code);
        return codeMap.get(code);
    }
}
